package vip.xiaonuo.smzq.modular.kcl.controller;

import javax.annotation.Resource;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import vip.xiaonuo.smzq.modular.kcl.entity.Kcp;
import vip.xiaonuo.smzq.modular.kcl.service.IKcpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import vip.xiaonuo.common.pojo.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * 矿产品
 *
 * @author eomer
 * @since 2024-02-22
 */
@Api(tags = "矿产品")
@RestController
@RequestMapping("/kcl/kcp")
@Validated
public class KcpController {

    @Resource
    private IKcpService iKcpService;

    /**
     * 添加矿产品
     */
    @ApiOperation("添加矿产品")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid Kcp kcp) {
        iKcpService.save(kcp);
        return CommonResult.ok();
    }

    /**
     * 删除矿产品
     */
    @ApiOperation("删除矿产品")
    @PostMapping("/delete")
    public CommonResult<String> delete(@ApiParam(name = "pkid", value = "主键") @RequestParam String pkid) {
        iKcpService.removeById(pkid);
        return CommonResult.ok();
    }

    /**
     * 编辑矿产品
     */
    @ApiOperation("编辑矿产品")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid Kcp kcp) {
        iKcpService.updateById(kcp);
        return CommonResult.ok();
    }

    /**
     * 矿产品分页查询
     */
    @ApiOperation("矿产品分页查询")
    @GetMapping("/list")
    public CommonResult<Page<Kcp>> page() {
        return CommonResult.data(iKcpService.page(new Kcp()));
    }


    /**
     * 矿产品详情查询
     */
    @ApiOperation("矿产品详情查询")
    @GetMapping("/getKcpList")
    public CommonResult<List<Kcp>> getKcpList(
            @ApiParam(name = "kqbm", value = "矿区编码",  required = true) @RequestParam String kqbm,
            @ApiParam(name = "djflbm", value = "登记分类编码",  required = true) @RequestParam Integer djflbm,
            @ApiParam(name = "nd", value = "年度",  required = true) @RequestParam Integer nd
    ) {
        return CommonResult.data(iKcpService.getKcpList(kqbm,djflbm,nd));
    }
}
